package main

import "fmt"

func printArray(arr [5]int) {
	arr[0] = 100
	for i := range arr { //获取下标index，使用range遍历
		fmt.Println(i)
	}
	for _, v := range arr { //只获取值
		fmt.Println(v)
	}
	for i, v := range arr { //rang可以同时获取数组的下标和值
		fmt.Println(i, v)
	}
}

func printArrayNew(arr *[5]int) {
	arr[0] = 100
	for i := range arr {
		fmt.Println(i)
	}
	for _, v := range arr {
		fmt.Println(v)
	}
	for i, v := range arr {
		fmt.Println(i, v)
	}
}

func main() {
	var arr1 [5]int                  //定义数组
	arr2 := [3]int{1, 3, 5}          //定义数组并赋初值
	arr3 := [...]int{2, 4, 6, 8, 10} //可变长度,确定后长度是固定的
	var grid [4][5]int               //多维数组4行5列[[0,0,0,0,0],[0,0,0,0,0],[0,0,0,0,0],[0,0,0,0,0]]

	fmt.Println("array definitions:")
	fmt.Println(arr1, arr2, arr3)
	fmt.Println(grid)

	fmt.Println("printArray(arr1)")
	printArray(arr1)

	fmt.Println("printArray(arr3)")
	printArray(arr3)

	fmt.Println("arr1 and arr3")
	fmt.Println(arr1, arr3)

	printArrayNew(&arr3)
}
